package com.heima.search.service.impl;

import com.heima.model.search.dtos.AssociateDto;
import com.heima.search.pojos.ApAssociateWords;
import com.heima.search.pojos.ApUserSearch;
import com.heima.search.service.AssociateService;
import com.heima.search.service.UserSearchService;
import com.heima.utils.thread.AppThreadLocalUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author brianxia
 * @version 1.0
 * @date 2022-09-20 15:48
 */
@Service
@Slf4j
public class AssociateServiceImpl implements AssociateService {

    @Autowired
    private MongoTemplate mongoTemplate;


    @Override
    public List<ApAssociateWords> search(AssociateDto dto) {
        return mongoTemplate.find(Query.query(Criteria.where("associateWords").regex(".*" + dto.getSearchWords() + ".*")).limit(dto.getPageSize()),
                ApAssociateWords.class
        );
    }
}
